﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface ISystemInfoService
    {
        IQueryable<SystemInfo> GetSystemInfos();
        SystemInfo GetSystemInfo(int id);
        void CreateSystemInfo(SystemInfo systemInfo);
        void DeleteSystemInfo(int id);
        void SaveSystemInfo();
    }
    
    public class SystemInfoService : ISystemInfoService
    {
        private readonly ISystemInfoRepository systemInfoRepository;
        private readonly IUnitOfWork unitOfWork;
        public SystemInfoService(ISystemInfoRepository systemInfoRepository, IUnitOfWork unitOfWork)
        {
            this.systemInfoRepository = systemInfoRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region ISystemInfoService Members

        public IQueryable<SystemInfo> GetSystemInfos()
        {
            var systemInfos = systemInfoRepository.GetAll();
            return systemInfos;
        }

        public SystemInfo GetSystemInfo(int id)
        {
            var systemInfo = systemInfoRepository.GetById(id);
            return systemInfo;
        }

        public void CreateSystemInfo(SystemInfo systemInfo)
        {
            systemInfoRepository.Add(systemInfo);
            SaveSystemInfo();
        }

        public void DeleteSystemInfo(int id)
        {
            var systemInfo = systemInfoRepository.GetById(id);
            systemInfoRepository.Delete(systemInfo);
            SaveSystemInfo();
        }

        public void SaveSystemInfo()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}